<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <a href="http://www.baidu.com">点我跳转百度</a>
    <script>
      //阻止默认事件
      //a标签有自己的默认事件  默认事件就是跳转行为
      //阻止默认行为
      //1. e.preventDefault();
      //2.return false  注意 : 一定要写在代码的最后
      // 3.IE8及以下:  e.returnValue = false

      var aEle = document.querySelector("a");
      aEle.onclick = function (e) {
        window.location.href = "http://www.sohu.com";
        //return false;
        //e.preventDefault();
        e.returnValue = false;
      };

      //阻止事件的传播(冒泡)
      //1.e.stopPropagation();
      //2.e.cancelBubble = true;
    </script>
  </body>
</html>
